new Vue({
    el: '#app',
    mixins: [Query],//组件配置文件，路径/utils/components.js
    data() {
        return {
            form: {//查询筛选
                value:'',
                PageNumber: 1, //页码
                RowAmount: 20,
                Condition: utf8ToBase64("%%"),
            },
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.getColumn(); //查询表头数据
         * 2.this.getList(this.form); //查询表格数据
         * 3.this.getTreeData();//查询树
         */
    },
    methods: {
        handleSerach() { //筛选
            this.form.Condition = utf8ToBase64(`%${this.form.value}%`);
            this.getList(this.form);
        },
        handleAdd(){//配置SQL
            sessionStorage.setItem("Url", "");
            window.location.href = './sql_config.html?action=Add'
        },
        handleEdit(row){//修改SQL
            try {
                const { primaryKey } = $('#table').data('options');
                window.location.href = "./sql_config.html?action=Modify&nodeKey=" + row[primaryKey];
            } catch (error) {
                console.error(error);
                this.$message({
                    message: '系统错误，请联系开发者!',
                    type: 'error'
                })
            }
        },
        handleRemove(row) { //点击删除
            this.$prompt("该操作将删除此条数据(" + row.SQL_SerialNumber + ")且无法恢复,请输入'确认删除'", '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                inputPattern: /^确认删除$/,
                inputErrorMessage: "请输入'确认删除'"
            }).then(() => {
                try {
                    const { primaryKey } = $('#table').data('options');
                    httpRequest({
                        hostApi:BASE_URL1,
                        url: '/generalQueryByTableNames',
                        data: {
                            Data: JSON.stringify({
                                base_sql_list: {
                                    Condition: `SQL_SerialNumber='${row[primaryKey]}'`,
                                    Original:'1'
                                },
                                base_sql_table_config: {
                                    Condition: `SQL_SerialNumber='${row[primaryKey]}'`,
                                    Original:'1'
                                }
                            })
                        },
                    }).then(res => {
                        if (res.Status == 'success') {
                            httpRequest({
                                hostApi:BASE_URL1,
                                url: '/generalDelete',
                                data: {
                                    Data: JSON.stringify(res.Data)
                                }
                            }).then(res => {
                                if (res.Status == "success") {
                                    this.getList(this.form);
                                    this.$message.success("删除成功");
                                } else {
                                    this.$message.error("删除失败，请重试！");
                                }
                            }).catch(xhr => {
                                this.$message({
                                    message: '系统错误，请联系开发者!',
                                    type: 'error'
                                })
                            })
                        } else {
                            this.$message({
                                message: '未获取到对应数据，请联系开发者!',
                                type: 'error'
                            })
                        }
                    }).catch(xhr => {
                        this.$message({
                            message: '系统错误，请联系开发者!',
                            type: 'error'
                        })
                    })
                } catch (error) {
                    console.error(error);
                    this.$message({
                        message: '系统错误，请联系开发者!',
                        type: 'error'
                    })
                }
            }).catch(() => { });
        },
    }
})